package com.cscp.javastudy.juc.lock;

/**
 * Demo用来理解可重入锁
 * Synchronized: 非公平锁，可重入锁
 */
public class LockDemo5 {
    public static void main(String[] args) {
        Phone5 phone = new Phone5();

        new Thread(()->{
            phone.sendSMS();
        },"A").start();

        new Thread(()->{
            phone.sendSMS();
        },"B").start();
    }
}

class Phone5{

    public synchronized void sendSMS(){
        System.out.println(Thread.currentThread().getName()+" sendSMS");
        call();//这里也有锁
    }

    public synchronized void call(){
        System.out.println(Thread.currentThread().getName()+" call");
    }
}
